# -*- coding: utf-8 -*-

import wsgiref.handlers

from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from BeautifulSoup import BeautifulSoup
from xmw.tianya import bot


from xmw.tianya import error_tianya
import os
import urllib2
import uuid

from xmw.tianya.bot import *
from google.appengine.ext import webapp
import global_setting

class MainPage(webapp.RequestHandler):
  def get(self):
      
      id=self.request.GET["post_id"]
      #id=id.decode('utf-8').encode('ascii')
      q=Post.all()
      q.filter("post_id =",id)
      #print type(id)
      p=q.get()
      if p is None:
          self.response.out.write("no such post")
      else:
          #import chardet
          #p.author=p.author.encode('ut'
          #print type(p.post_id)
          #print p.post_id
          #print id
          template_values = {
                               "post":p
                               }
          path = os.path.join(global_setting.base_dir, 'portal/template/post.html')
          self.response.out.write(template.render(path, template_values))          
          
      #self.response.out.write(t)


def main():
    application = webapp.WSGIApplication(
                                       [('/show_post', MainPage)],
                                       debug=True)
    wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":
  main()